﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.controllers {
    import flash.events.*;
    import flash.geom.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.world.vos.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;
    import net.wooga.pets.controllers.startup.*;

    public class LevelUpCommand extends Command {

        public var event:InfoEvent;
        public var tutorialModel:TutorialModel;
        public var sessionModel:SessionModel;
        public var gameStateModel:GameStateModel;
        public var roomslotsModel:RoomSlotsModel;
        public var levelModel:LevelModel;
        public var computerModel:ComputerModel;
        public var userModel:UserModel;
        public var gameViewModel:GameViewModel;

        override public function execute():void{
            var _local1:int = this.userModel.level;
            if (_local1){
                dispatch(new TrackingEvent(TrackingConst.TRACK, TrackingConst.SET_LEVEL));
                log(("c level: " + _local1));
                switch (_local1){
                    case 2:
                        this.gameViewModel.setGameScaleByIndex(GameViewModel.SCALE_3X3);
                        dispatch(new Event(EventConstants.CENTER_GAMEVIEW));
                        this.gameViewModel.gameViewPosition = new Point((this.gameViewModel.gameViewPosition.x + 105), -120);
                        this.tutorialModel.state = TutorialModel.ROOMTUTORIAL_START_TUTORIAL;
                        break;
                };
                l("check kiosk tutorial");
                dispatch(new InfoEvent(EventConstants.CHECK_KIOSK_TUTORIAL, null, TutorialModel.KIOSK_START_TUTORIAL));
                l("check fountain tutorial");
                dispatch(new InfoEvent(EventConstants.CHECK_FOUNTAIN_TUTORIAL, null, {state:TutorialModel.FOUNTAIN_START_TUTORIAL}));
                l("check kindergarten tutorial");
                dispatch(new InfoEvent(EventConstants.CHECK_KINDERGARTEN_TUTORIAL, null, TutorialModel.KINDERGARTEN_START_TUTORIAL));
            };
            dispatch(new Event(EventConstants.UPDATE_MORE_PETS_ARROW));
            dispatch(new Event(EventConstants.CHECK_LETTERS));
            var _local2:InfoEvent = new InfoEvent(EventConstants.CREATE_POPUP, GameConstants.LEVEL_UP_POPUP, this.event.info);
            dispatch(_local2);
            dispatch(new InfoEvent(EventConstants.PLAY_EFFECT_SOUND, GameConstants.SOUND_NEW_LEVEL));
            this.checkPreload(_local1);
            this.checkAssets(_local1);
        }
        private function checkPreload(_arg1:int):void{
            var _local2:LevelVO = this.levelModel.getLevelDataByNumber(_arg1);
            var _local3:RequestEvent = new RequestEvent(EventConstants.SEND_REQUEST);
            if (_local2.room){
                _local3.addAssetRequest(ProtocolConstants.LOAD_ROOM, _local2.room.toLowerCase(), ProtocolConstants.PRELOADING_PIPE);
            };
            var _local4:String = this.computerModel.getNewPetInLevel(_arg1);
            if (_local4){
                _local3.addAssetRequest(ProtocolConstants.LOAD_PATIENT, _local4, ProtocolConstants.PRELOADING_PIPE);
            };
            dispatch(_local3);
            dispatch(new Event(EventConstants.PRELOAD_LEVELUP_ICON));
        }
        private function checkAssets(_arg1:int):void{
            var _local2:RequestEvent = new RequestEvent(EventConstants.SEND_REQUEST);
            switch ((_arg1 - 1)){
                case 4:
                    _local2.addAssetRequest(ProtocolConstants.LOAD_ASSET, GameConstants.FOUNTAIN_ASSETS, ProtocolConstants.PRELOADING_PIPE);
                    break;
            };
            dispatch(_local2);
        }
        private function centerGameView(_arg1:int):void{
            this.gameViewModel.setGameScaleByIndex(_arg1);
            dispatch(new Event(EventConstants.CENTER_GAMEVIEW));
            this.gameViewModel.gameViewPosition = new Point((this.gameViewModel.gameViewPosition.x + 100), -120);
        }

    }
}//package net.wooga.pets.controllers 
